package com.fhz.a2102high6

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.fhz.a2102high6.test2.Fail11
import com.fhz.a2102high6.test2.Result1
import com.fhz.a2102high6.test2.Study
import com.fhz.a2102high6.test2.Success1
import com.fhz.a2102high6.test3.abc
import com.fhz.a2102high6.test3.beginWith
import com.fhz.a2102high6.test3.method
import com.fhz.a2102high6.test3.open
import javax.security.auth.callback.Callback
import kotlin.properties.Delegates

typealias aIIner  = A.Inner

class MainActivity : AppCompatActivity() {
    lateinit var user:Useer
    lateinit var study:Study
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        study.doHomework()





        user = Useer("小明",12)

        user.age //控制

        val student = Student()
        student.name = "112"

        student.isEmpty = false

        study.readBooks()

        student.test { a, b -> a + b }

        student.test(object : Human{
            override fun add(a: Int, b: Int): Int {
              return a + b
            }
        })


        val name = "a121"
        name.print()

        var a=10



        val list = mutableListOf("Apple", "Banana", "Orange", "Pear", "Grape")
        list.add("2")
        for(li in list){
            list.remove(li)
        }


        val mutableSetOf = mutableSetOf<String>()
        mutableSetOf.add("12")
        mutableSetOf.add("12")


        val map = mutableMapOf<String,String>()
        map["one"] = "one"
        map.put("two","two")


        for (l in list){
            println(l)
        }
        list.filter { it.startsWith("B") }
            .forEach { println(it) }



        getSharedPreferences("da", MODE_PRIVATE).edit().open{
            putString("name","xiaoming")
            putInt("age",12)
            apply()
        }



        //并发
        Thread {
            println(1)
        }.start()

        Thread {
            println(2)
        }.start()

        Thread {
            println(3)
        }.start()

        Thread {
            println(4)
        }.start()

        //1234
        //重量级

        //线程的随机性
        //cpu
        /**
         * 1
         * 2
         * 3
         * 4
         */

        //重量级




        if("abc".beginWith("a")){

        }

        if("abc" beginWith "a"){

        }







    }

    fun eval(expr: ResultFeng): ResultFeng = when(expr) {
        is Success -> Success(1)
        is Fail -> Fail(0)
        // 不再需要 `else` 子句，因为我们已经覆盖了所有的情况
        is Loading -> Loading(1)
        is ErrorFeng -> ErrorFeng
    }

    fun test(result: Result1) = when(result){
        is Success1 -> println(1)
        is Fail11 -> println(1)
    }

}